package task.dataObjects
{
	import common.utils.DateManager;
	
	import mx.collections.ArrayCollection;
	[Bindable]
	public class TaskHeaderDO
	{
		public var INTERNAL_TASK_NUM:String = "0";
		public var WAREHOUSE:String = "";
		public var COMPANY:String = "";
		public var TASK_ID:String = "";
		public var TASK_TYPE:String = "";
		public var INTERNAL_TASK_TYPE:String = "";
		public var REFERENCE_NUM:String = "";
		public var REFERENCE_ID:String = "";
		public var REFERENCE_NUM_TYPE:String = "";
		public var ASSIGNED_USER:String = "";
		public var COMPLETE_USER:String = "";
		public var CONDITION:String = "";
		public var HOLD_CODE:String = "";
		public var USER_STAMP:String = "";
		public var DATE_TIME_STAMP:String = DateManager.GetTodayString();
		public var INTERNAL_WAVE_NUM:String = "0";

		public function TaskHeaderDO(){		
		}
		
		public function Init(xmlObj:XML):void
		{
			if(null == xmlObj)
				return;
			else{
				for each (var itemProp:XML in xmlObj.children()) {
					//Use XML node name to reference matching property in value object				
					this[itemProp.name()] = itemProp;
				}
			}
		}
		
		public function ToXML():XML{
			var xmlObj:XML = 
				<TASK_HEADER>			
					<INTERNAL_TASK_NUM>{INTERNAL_TASK_NUM}</INTERNAL_TASK_NUM>
					<WAREHOUSE>{WAREHOUSE}</WAREHOUSE>
					<COMPANY>{COMPANY}</COMPANY>
					<TASK_ID>{TASK_ID}</TASK_ID>
					<TASK_TYPE>{TASK_TYPE}</TASK_TYPE>
					<INTERNAL_TASK_TYPE>{INTERNAL_TASK_TYPE}</INTERNAL_TASK_TYPE>
					<REFERENCE_NUM>{REFERENCE_NUM}</REFERENCE_NUM>
					<REFERENCE_ID>{REFERENCE_ID}</REFERENCE_ID>
					<REFERENCE_NUM_TYPE>{REFERENCE_NUM_TYPE}</REFERENCE_NUM_TYPE>
					<ASSIGNED_USER>{ASSIGNED_USER}</ASSIGNED_USER>
					<COMPLETE_USER>{COMPLETE_USER}</COMPLETE_USER>
					<CONDITION>{CONDITION}</CONDITION>
					<HOLD_CODE>{HOLD_CODE}</HOLD_CODE>
					<USER_STAMP>{USER_STAMP}</USER_STAMP>
					<DATE_TIME_STAMP>{DATE_TIME_STAMP}</DATE_TIME_STAMP>
					<INTERNAL_WAVE_NUM>{INTERNAL_WAVE_NUM}</INTERNAL_WAVE_NUM>
				</TASK_HEADER>;
			return xmlObj;
		}			

		public static function getTaskHeaders(list:XMLList):ArrayCollection
		{
			var ac:ArrayCollection = new ArrayCollection();
			for each(var xml:XML in list)
			{
				var tskHdr:TaskHeaderDO = new TaskHeaderDO();
				tskHdr.Init(xml);
				ac.addItem(tskHdr);
			}
			return ac;
		}
	}
}